<?php
class Grid extends Container {
	
	private static $twoColumnClass = 'ui-grid-a';
	private static $threeColumnClass = 'ui-grid-b';
	private static $fourColumnClass = 'ui-grid-c';
	private static $fiveColumnClass = 'ui-grid-d';
	
	private static $blockClassArray = array(1 => 'ui-block-a',
											2 => 'ui-block-b',
											3 => 'ui-block-c',
											4 => 'ui-block-d',
											5 => 'ui-block-e');
	
	private $gridColumns;
	
	public function __construct($elementId, $gridColumns) {
		
		parent::__construct($elementId);
		
		$this->gridColumns = $gridColumns;
	}
	
	public function addElement($element) {
		
		$elementNumber = count($this->elementArray);
		$blockClassIndex = $elementNumber % $this->gridColumns + 1;
		
		parent::addElement(new GridElement($this->elementId . '_' . $elementNumber,
											self::$blockClassArray[$blockClassIndex], $element));
	}
	
	public function addGridElement(GridElement $gridElement) {
		
		parent::addElement($gridElement);
	}
 	
	private function getGridClassValue($gridColumns) {
		
		switch ($gridColumns) {
			case GridColumns::$twoColumn:
				return self::$twoColumnClass;
				
			case GridColumns::$threeColumn:
				return self::$threeColumnClass;
				
			case GridColumns::$fourColumn:
				return self::$fourColumnClass;
				
			case GridColumns::$fiveColumn:
				return self::$fiveColumnClass;
		}
	}
	
	protected function renderOpeningMarkup() {
		
		echo '<div ', $this->formatAttributes(),
			 ' class="', $this->getGridClassValue($this->gridColumns), '" >';
	}
	
	protected function renderClosingMarkup() {
		
		echo '</div>';
	}
	
}